﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using Microsoft.Ted.Wacel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace Microsoft.Ted.Wacel.Demo.Web.Controllers
{
    public class RandomCubeDataController : ApiController
    {
        
        [HttpGet]
        public List<PerfData> GetHour(int id)
        {
            Cache.Cube mCachedCube = new Cache.Cube("RandomCube");
            mCachedCube.AddDimension(Dimension.GetTimeDimensionMonthDayHour5Minutes(DateTime.UtcNow.Year));
            mCachedCube.AddDimension(Dimension.CreateFreeDimension("Slot"));
            var data = mCachedCube.Query(new { Time = Dimension.GetHourTimeKey(DateTime.UtcNow), Slot = "Slot"+ id.ToString() });
            var dataPoints = mCachedCube.Drilldown(data, "Time");
            var list = from v in dataPoints
                       select new PerfData { 
                           Time = v.Coordinates[0].Name,
                           Value = v.Average };
            var retList = list.ToList();
            retList.Add(new PerfData { Time = data.Coordinates[0].Name, Max = data.Max, Min = data.Min });
            return retList;
        }
        [HttpGet]
        public List<PerfData> GetDay(int id)
        {
            Cache.Cube mCachedCube = new Cache.Cube("RandomCube");
            mCachedCube.AddDimension(Dimension.GetTimeDimensionMonthDayHour5Minutes(DateTime.UtcNow.Year));
            mCachedCube.AddDimension(Dimension.CreateFreeDimension("Slot"));
            var data = mCachedCube.Query(new { Time = Dimension.GetDayTimeKey(DateTime.UtcNow), Slot = "Slot" +id.ToString() });
            var dataPoints = mCachedCube.Drilldown(data, "Time");
            var list = from v in dataPoints
                       select new PerfData
                       {
                           Time = v.Coordinates[0].Name,
                           Value = v.Average
                       };
            var retList = list.ToList();
            retList.Add(new PerfData { Time = data.Coordinates[0].Name, Max = data.Max, Min = data.Min });
            return retList;
        }
    }
    public class PerfData
    {
        public string Time { get; set; }
        public double Value {get;set;}
        public double Min { get; set; }
        public double Max { get; set; }
    }
}
